//
//  AccountVC.m
//  Ginix
//
//  Created by ff on 2025/3/10.
//

#import "AccountVC.h"
#import "AccountListCell.h"
#import "ForgetPassVC.h"
@interface AccountVC ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong) UITableView * listView;
@property (nonatomic,strong) HomeTipsView * tipsView;
@end

@implementation AccountVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setSubViewLayout];
}

-(void)setSubViewLayout{
    
    self.title = @"账号安全";
    [self.view addSubview:self.listView];
    
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 2;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
        
   
    return  56 * FMScaleX;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    AccountListCell * cell = [tableView dequeueReusableCellWithIdentifier:@"AccountListCell"];
    [cell setIndex:indexPath.row];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
   
    if (indexPath.row == 1) {
        [self.tipsView startAnimationWithTitle:@"注销账号" info:@"确定注销当前账号吗？注销后相关数据会立即清除"];
        self.tipsView.enterdBtnBlock = ^{
            [SPNetworkingIns GET:PORT(@"auth-center/api/log/revokeToken") params:@{} success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull responseObject, NSInteger code) {
                [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"isLogin"];
                [(AppDelegate*) [UIApplication sharedApplication].delegate gotoApp];
                [(AppDelegate*) [UIApplication sharedApplication].delegate gotoLogin];
                [[BCLRingManager shared] disconnect];
            } fail:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
                
            }];
        };
    }
    if (indexPath.row == 0) {
        ForgetPassVC * vc = [[ForgetPassVC alloc]init];
        vc.type = 1;
        [self.navigationController pushViewController:vc animated:YES];
    }
}


-(UITableView *)listView{
    
    if (!_listView) {
        _listView = [[UITableView alloc]initWithFrame:CGRectMake(0, NavHeight + 10, WIDTH, HEIGHT - NavHeight - kSafeAreaHeight - 180 * FMScaleX)];
        _listView.delegate = self;
        _listView.dataSource = self;
        _listView.showsVerticalScrollIndicator = NO;
        _listView.showsHorizontalScrollIndicator = NO;
        _listView.backgroundColor = UIColor.clearColor;
        _listView.separatorStyle = UITableViewCellSeparatorStyleNone;
        [_listView registerClass:[AccountListCell class] forCellReuseIdentifier:@"AccountListCell"];
    }
    return _listView;
}
-(HomeTipsView *)tipsView{
    
    if (!_tipsView) {
        _tipsView = [[HomeTipsView alloc]initWithFrame:self.view.bounds];
        [self.view addSubview:_tipsView];
    }
    return _tipsView;
}
@end
